// Created by wangliang on 2025/6/19.

import 'package:flutter/material.dart';
import 'package:flutter_app_demo/base/base_view_model.dart';
import 'package:flutter_app_demo/helper/account_helper.dart';
import 'package:flutter_app_demo/helper/route_helper.dart';
import 'package:mvvm_plus/mvvm_plus.dart';

class SplashPage extends ViewWidget<SplashPageViewModel> {
  SplashPage({super.key}) : super(builder: () => SplashPageViewModel());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Container(),
    );
  }
}

class SplashPageViewModel extends BaseViewModel {
  @override
  void initState() async {
    super.initState();
    await AccountHelper.instance.loadAccount();
    if (AccountHelper.instance.isLogin()) {
      launchMain();
    } else {
      launchLogin();
    }
  }

  launchLogin() => RouteHelper.instance.replace(context, '/login');
  launchMain() => RouteHelper.instance.replace(context, '/home');
}
